* ======================================
* --------- Baseline results -----------
* ======================================


	use $dta\EstimationSample.dta, clear


* Estimate models
* ===============	
	
	egen idbsu = group(Voter_id Voter_bsu)
	gen period = 1*(year == 2019)
	xtset idbsu period
	estimates clear	
	
	
	foreach net in Fam1 Fam2 Work1 Work2 Imm1 Imm2 {
	
		preserve
	
		keep if `net' == 1 	// set sample 
	
		sum Voter_turnout 	// mean depvar
		local meandepvar = string(r(mean)*100, "%15.2fc")
	
		gen Any = `net'Any
		gen Same = `net'Same
		eststo baseline_`net': xtreg Voter_turnout Any Same i.period, ///
			i(idbsu) fe cluster(Voter_bsu)
		quietly estadd local meandep `meandepvar', replace

		restore
	}


* Export table
* ============

	esttab baseline* ///
		using $tbls\Baseline.tex, replace  style(tex) ///
		prehead("\begin{tabular}{l*{7}{c}} \hline\hline \\  ") ///
		posthead("\hline \\") ///
		fragment ///
		mtitles("Close" "Extended" "Age-estbl." "Estbl." "3-digit" "2-digit") ///
		mgroups("\shortstack{\\ Family}" "\shortstack{\\ \\ Co-workers}" ///
			"\shortstack{\\ \\ Immigrants}", pattern(1 0 1 0 1 0) ///
			span prefix(\multicolumn{@span}{c}{) suffix(}) ///
			end(\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7})) ///
		label se b(%9.3f) se(%9.3f) nostar ///
		refcat(Any "\shortstack{ No candidate in network }") ///
		coeflabels(Any "Any District" Same "Same District" ) ///
		drop(_cons *.period ) noomitted nobaselevels ///
		nonotes stats(N N_clust meandep, labels( ///
			"Observations" "Clusters" "Mean turnout (\%)") ///
			fmt(%15.0fc %15.0fc %15.0fc)) ///
			substitute(\_ _) ///
		prefoot("\hline") ///
		postfoot("\hline\hline \\ \end{tabular}")
